# include "game.h"

s_player    *g_player_1 = NULL;

int player_update(SDL_Surface *area)
{
  if (g_player_1->coord.x < 0)
    g_player_1->coord.x = 0;
  if (g_player_1->coord.x + g_player_1->size.x > area->w)
    g_player_1->coord.x = area->w - g_player_1->size.x;
  if (g_player_1->coord.y < 0)
    g_player_1->coord.y = 0;
  if (g_player_1->coord.y + g_player_1->size.y > area->h)
    g_player_1->coord.y = area->h - g_player_1->size.y;
  draw_rect(g_player_1->coord.x, g_player_1->coord.y, g_player_1->skin[0], area);

  if (g_player_1->health <= 0)
    return (0);
  else
    return (1);
}

int player_init(int x, int y)
{
  s_wlist *weapons = malloc(sizeof(s_wlist));
  s_weapon *currentw = malloc(sizeof(s_weapon));

  SDL_Surface **skin = malloc(2 * sizeof(SDL_Surface*));
  skin[0] = IMG_Load("src/picture/star_ship.png");
  skin[1] = IMG_Load("/src/picture/Star_ship_destroy.png");

  g_player_1 = malloc(sizeof(s_player));
  g_player_1->health = 300;
  g_player_1->coord.x = x;
  g_player_1->coord.y = y;
  g_player_1->size.x = skin[0]->w;
  g_player_1->size.y = skin[0]->h;
  g_player_1->speed = 10;
  g_player_1->skin = skin;
  g_player_1->alive = 1;
  g_player_1->weapons = weapons;
  g_player_1->currentw = currentw;
  return (0);
}
